<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="ctx" th:content="${#httpServletRequest.getContextPath()}"/>
    <title>首页</title>
    <link rel="stylesheet" th:href="@{/css/admin/base-v2.css}">
    <link rel="stylesheet" th:href="@{/lib/font-awesome/4.7.0/css/font-awesome.min.css}">
    <link rel="stylesheet" th:href="@{/css/admin/app.css}">
    <style>
        .info {
            display: flex;
        }

        .info-item {
            flex: 1;
            text-align: center;
        }

        .info-item span {
            color: #333;
            font-size: 24px;
        }

        .info-item a span:hover {
            color: #108ee9;
        }

        .link{
            overflow: hidden;
        }

        .link-group {
            margin-bottom: 20px;
            float: left;
            width: 50%;
        }

        .link-group-title {
            color: #333;
            font-size: 16px;
            margin-bottom: 15px;
        }

        .link-item {
            margin-right: 25px;
        }

        .link-item:hover {
            color: #108ee9;
        }

        .link-left,
        .link-right {
            width: 50%;
        }

        .link-left {
            padding-right: 20px;
        }

        .link-right {
            padding-left: 20px;
        }
    </style>
</head>

<body>

<div class="app-page">
    <div class="app-page-header">
        <div class="page-title">
            <div class="title">首页</div>
        </div>
    </div>

    <div class="app-page-content">
        <div class="app-card z-mab">
            <div class="app-card-head">
                <div class="app-card-title">实时概况</div>
                <div class="app-card-subtitle">更新时间：<span th:text="${currentDate}"></span></div>
            </div>
            <div class="app-card-body">
                <div class="info">
                    <div class="info-item">
                        <p>广告发布数</p>
                        <a th:href="@{/programJson/listPage}"><span th:text="${programJsonCount}"></span></a>
                    </div>
                    <div class="info-item">
                        <p>发布异常数</p>
                        <a th:href="@{/programJson/listPage}"><span th:text="${failureCount}"></span></a>
                    </div>
                    <div class="info-item">
                        <p>联网终端数</p>
                        <a th:href="@{/deviceInfo/listByPage}"><span th:text="${onlineDeviceCount}">100</span></a>
                    </div>
                    <div class="info-item">
                        <p>异常终端数</p>
                        <a th:href="@{/deviceInfo/listByPage}"><span th:text="${offlineDeviceCount}"></span></a>
                    </div>
                </div>
            </div>
        </div>
        <div class="app-card z-mab">
            <div class="app-card-head">
                <div class="app-card-title">快速入口</div>
            </div>
            <div class="app-card-body">
                <div id="vue-app">
                    <div class="link">
                        <link-group v-for="item in menu.data" :group="item" :context="menu.context"></link-group>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script th:src="@{/lib/jquery.min.js}"></script>
<script th:src="@{/lib//vue/v2.5.16/vue.min.js}"></script>
<script th:src="@{/js/admin/home.js}"></script>
<script type="text/javascript" th:inline="javascript">
    //获取context path
    var context = $("meta[name='ctx']").attr("content") || '';
    $.ajax({
        type: 'post',
        dataType: 'json',
        url: context +'/web/getMenuDatas',
        data: {},
        cache: false,
        async: true,
        success: function (result) {
            data = result.data;
            //不显示首页
            for (var i = 0; i < data.length; i ++) {
                var obj = data[i];
                var url = obj["url"];
                if ("/web/goHome" ==  url) {
                    data.splice(i, 1);
                    break;
                }
            }
            vueApp.menu = {
                data: data,
                context:context
            }
        }
    });
</script>

</body>

</html>